﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using Sebarf.Core.Interfaces;
using Sebarf.Core.Internal;
using Sebarf.Diagnostics.Interfaces;
using Sebarf.Services.Interfaces;

#endregion

namespace Sebarf.Services.Impl {
	/// <summary>
	/// Description of the class
	/// </summary>
	public class ResolveServicesDependenciesRequestHandler : RequestHandler<ResolveServicesDependenciesRequest> {
		#region Public Methods

		protected override object OnProcessRequest(ResolveServicesDependenciesRequest request,
													IServiceLocatorService serviceLocator) {
			Check.AssertException(serviceLocator.IsServiceAvailable<IDiagnosticsServiceLocatorService>(),
								   "IDiagnosticsServiceLocatorService has to be available");
			var service = serviceLocator.GetRegisteredService<IDiagnosticsServiceLocatorService>();
			var localEngine = serviceLocator.GetRegisteredService<IRequestHandlerEngineLocatorService>();
			IServiceImpl[] services = service.GetAllRegisteredServices<IServiceImpl>();
			foreach (IServiceImpl serv in services) {
				localEngine.GetLocalEngine().Process(new ResolveDependenciesRequest { ResolveMyReferences = serv });
			}
			return true;
		}

		#endregion
	}
}